package com.fruit.servlets;

import com.fruit.dao.FruitDao;
import com.fruit.dao.impl.FruitDaoImpl;
import com.fruit.pojo.Fruit;
import com.myssm.myspringmvc.ViewBaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends ViewBaseServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        FruitDao fruitDao = new FruitDaoImpl();
        //1、查询所欲列表数据
        List<Fruit> fruitList = fruitDao.getFruitList();
        //2、保存到session作用域
        HttpSession session = req.getSession();
        session.setAttribute("fruitList", fruitList);
        // 此处的视图名称是  index
        //那么thymeleaf会将这个 逻辑视图名称 对应到 物理视图名称上去
        // 逻辑视图名称： index
        // 物理视图名称 ：view-prefix + 逻辑视图名称 + view-suffix
        // 其实对应到真实的项目中就是 ：/   index   .html

        super.processTemplate("index", req, resp);


    }
}
